package com.cheyun.netsalev3.viewmodel

import android.content.Intent
import android.view.View
import androidx.lifecycle.Transformations
import com.cheyun.netsalev3.bean.Row
import com.cheyun.netsalev3.repository.CuesAllocationPageRepository
import com.cheyun.netsalev3.view.defeatdetails.DefeatDetailsActivity

/**
 * @author Michael
 * @date  2018/12/26 - 15:34.
 */
class CuesAllocationActivityViewModel(var cuesAllocationRepository: CuesAllocationPageRepository) : BaseViewModel() {
    var listData = cuesAllocationRepository.loadAndroidData()
    var networkState= Transformations.switchMap(listData){
        cuesAllocationRepository.networkState
    }!!
    fun onClickItem(view:View,item: Row){
        var intent = Intent(view.context, DefeatDetailsActivity::class.java)
        intent.putExtra("tid", item.tid)
        intent.putExtra("nkey", "archive.index")
        view.context.startActivity(intent)
    }

    fun refresh() {
        cuesAllocationRepository.dataSourceFactory.sourceLiveData.value?.invalidate()
    }
}